#include <bits/stdc++.h>
using namespace std;
bool ischaosu[1000005];
int n,m,l,v;
int a[100005][3];
int p[100005];
int main()
{
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    int t;
    cin >> t;
    while(t--)
    {
        memset(ischaosu,0,sizeof(ischaosu));
        cin >> n >> m >> l >> v;
        int cnt=0;
        for (int i=1;i<=n;i++)
        {
            cin >> a[i][0] >> a[i][1] >> a[i][2];
            if(a[i][1]>v) cnt++;
        }
        cout << cnt << " ";
        for (int i=1;i<=m;i++)
        {
            cin >> p[i];
        }
        cout << m-(cnt!=0) << endl;
    }
    fclose(stdin);
    fclose(stdout);
    return 0;
}
